<template>
	<view>
		<u-cell-group v-if="data.length > 0" :customStyle="{'background-color': '#fff'}">
			<u-cell v-for="(item,index) in data" :key="index" :title="item.title" isLink @click="policy(item.id)">
				<u-icon slot="icon" size="30" color="#a0cfff" :name="realm_name + item.images"></u-icon>
				<text v-if="item.total > 0" slot="value" class="u-slot-value">{{item.total}}</text>
			</u-cell>
		</u-cell-group>
		<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
		</u-empty>
	</view>
</template>

<script>
	var util = require('@/util/request.js');
	export default {
		data() {
			return {
				realm_name: '',
				data: []
			}
		},
		onLoad() {
			this.realm_name = util.API_URL
			this._request()
		},
		onShow() {
			this._request()
		},
		methods: {
			async _request() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'Setting/getProductAllocationCount'
				});
				if (res.code == 200) {
					this.data = res.data
					if (this.data.length == 1) {
						this.policy(this.data[0].id)
					}
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000
					})
				}
			},
			policy(id) {
				uni.navigateTo({
					url: '/pages/index/exchange/list?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.u-slot-value {
		color: red;
	}
</style>